﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using MCWEBSITE.ENTITY;
using MCWEBSITE.BUL;

public partial class Modules_HugKid_wucProductDetails : System.Web.UI.UserControl
{
    private int productType = 0;

    protected void Page_Load(object sender, EventArgs e)
    {
        int productId = 0;

        if (Request.QueryString["ProductId"] != null)
        {
            productId = Convert.ToInt32(Request.QueryString["ProductId"].ToString());
        }

        //btnBuy.Attributes.Add("onclick", "AddCookie(" + productId + ")");
        ltBuy.Text = "<a href=\"javascript: void(0)\" onclick=\"AddCookie(" + productId + ")\"><img src=\"App_Themes/HugKidTheme/images2/dathang.jpg\" /></a>";

        if (productId != 0) {
            BindProductDetails(productId);
            BindSameProduct();
        }        
    }

    //ảnh đại diện: 300x300; 3 ảnh nhỏ ở dưới: 50x50
    //Thứ tự insert ảnh: ảnh 1: ảnh đại diện, ảnh 2: ảnh to, ảnh 3: ảnh nhỏ ở dưới
    protected void BindProductDetails(int ProductID) { 
        websiteProductInfo objProduct = websiteProductBUL.Load(ProductID);

        if (objProduct.ItemName.Length > 20)
        {
            lbProductName.Text = objProduct.ItemName.Substring(0, 20);
        }
        else {
            lbProductName.Text = objProduct.ItemName;
        }        
        lbProductCode.Text = objProduct.ItemCode;
        lbPrice.Text = objProduct.Atribute1;
        lbDiscount.Text = objProduct.Atribute5;
        double temp = double.Parse(objProduct.Atribute1) - double.Parse(objProduct.Atribute5);
        lbSave.Text = temp.ToString();
        lbDescription.Text = objProduct.Description;
        productType = objProduct.TypeID;

        lbMagicZoom.Text = "<a href=\"" + objProduct.Image + "\" class=\"MagicZoom\" rel=\"zoom-width: 3000; zoom-height: 3000; "
            +"zoom-position: inner\" id=\"Zoomer\" title=\"Áo Sơ Mi LEVI'S\"> <img src=\"" + objProduct.Atribute2.Split('#')[0] + "\" /></a>";
        if (objProduct.Atribute2 != null && objProduct.Atribute2.Length > 0)
        {
            lbSubMagicZoom1.Text = "<a style=\"margin-right: 15px\" href=\"" + objProduct.Image + "\" rel=\"zoom-id:Zoomer;\""
            + " rev=\"" + objProduct.Atribute2.Split('#')[0] + "\"><img src=\"" + objProduct.Atribute2.Split('#')[1] + "\" /></a>";
        }
        if (objProduct.Atribute3 != null && objProduct.Atribute3.Length > 0) {
            lbSubMagicZoom2.Text = "<a style=\"margin-right: 15px\" href=\"" + objProduct.Atribute3.Split('#')[0] + "\" rel=\"zoom-id:Zoomer;\""
            + " rev=\"" + objProduct.Atribute3.Split('#')[1] + "\"><img src=\"" + objProduct.Atribute3.Split('#')[2] + "\" /></a>";
        }
        if (objProduct.Atribute4 != null && objProduct.Atribute4.Length > 0) {
            lbSubMagicZoom3.Text = "<a style=\"margin-right: 15px\" href=\"" + objProduct.Atribute4.Split('#')[0] + "\" rel=\"zoom-id:Zoomer;\""
            + " rev=\"" + objProduct.Atribute4.Split('#')[1] + "\"><img src=\"" + objProduct.Atribute4.Split('#')[2] + "\" /></a>";
        }        
    }

    protected void BindSameProduct() {
        dlSameProductList.DataSource = websiteProductBUL.GetByLanguageAndTypeDS(productType, "1", "vi-VN");
        dlSameProductList.DataBind();
    }
}
